/*

 * Copyright (C) 2021 Huawei Device Co., Ltd.

 * Licensed under the Apache License, Version 2.0 (the "License");

 * you may not use this file except in compliance with the License.

 * You may obtain a copy of the License at

 *

 *     http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "AS IS" BASIS,

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and

 * limitations under the License.

 */
package com.aries.ui.widget.demo.slice;

import com.aries.ui.widget.demo.ResourceTable;
import com.aries.ui.widget.demo.base.BaseAbilitySlice;
import com.aries.ui.widget.demo.module.tab.CommonTabAbility;
import com.aries.ui.widget.demo.module.tab.SegmentTabAbility;
import com.aries.ui.widget.demo.module.tab.SlidingTabAbility;
import com.aries.ui.widget.demo.module.tab.adapter.SimpleHomeAdapter;

import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;

import ohos.agp.colors.RgbPalette;
import ohos.agp.components.Component;
import ohos.agp.components.ListContainer;

public class SimpleTabAbilitySlice extends BaseAbilitySlice {
    private ListContainer listContainer;
    private final String[] mItems = {"SlidingTabLayout", "CommonTabLayout", "SegmentTabLayout"};
    private final Class<?>[] mClasses = { SlidingTabAbility.class,  CommonTabAbility.class,
             SegmentTabAbility.class};

    @Override
    protected void setTitleBar() {
        titleBar.setTitleMainText("TabLayout示例").setStatusBackgroundColor(RgbPalette.WHITE.asArgbInt());
    }

    @Override
    protected void initView(Intent intent) {
        listContainer = (ListContainer) findComponentById(ResourceTable.Id_lv_container_simple_tab);
        initData();
    }

    @Override
    protected int getLayout() {
        return ResourceTable.Layout_ability_simple_tab;
    }

    private void initData() {
        SimpleHomeAdapter simpleHomeAdapter = new SimpleHomeAdapter(getContext(), mItems);
        listContainer.setItemProvider(simpleHomeAdapter);
        listContainer.setItemClickedListener(new ListContainer.ItemClickedListener() {
            @Override
            public void onItemClicked(ListContainer listContainer, Component component, int i, long l) {
                Intent intent = new Intent();
                Operation build = new Intent.OperationBuilder()
                        .withBundleName("com.aries.ui.widget.demo")
                        .withAbilityName(mClasses[i])
                        .build();
                intent.setOperation(build);
                startAbility(intent);
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
